let app = getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        detail: {
            type: Object,
            value: {},
            observer: 'watch'
        },
        yejian: {//夜间
            type: Boolean,
            value: false,
        },
        submit: {//是否提交
            type: Boolean,
            value: false,
        },
        items: {
            type: Object,
            value: {}
        },
        type: {
            type: Number,
            value: 0
        },
        num: {
            type: Number,
            value: 0
        }
    },
    observers: {
        'detail': function (new_val) {
            // this.monitor_detail(new_val)
        }
    },
    /**
     * 组件的初始数据
     */
    data: {
        my_answer: '',// 答案
        flage: false,//是否显示答案
        fen: 0,//自己填的分数
        fenshu_arr: [],
        df_popShow: false,
        subjectInfo: {}

    },

    //ask_id	1	是	string	小问项id
    // fraction	3	是	string	小问得分
    // answer_content	回答内容	是	string	回答内容

    /**
     * 组件的方法列表
     */
    methods: {
        watch(new_val, old_val) {
            this.get_mk_subject_info(new_val.subject_id)
        },
        //获取题目详情
        get_mk_subject_info(subject_id) {
            wx.$request(wx.$api.mk_subject_info, {
                subject_id,
                
            }).then(res => {
                this.setData({
                    subjectInfo: res
                })
            })
        },
        monitor_detail(new_val) {
            console.log('题目详情', new_val);
            let fen_arr = [];
            let fraction_total = new_val.fraction_total
            for (let i = 0.5; i <= fraction_total; i += 0.5) {
                fen_arr.push(i)
            }
            this.setData({
                fenshu_arr: fen_arr
            })
            if (new_val.subject_log) {
                this.setData({
                    my_answer: new_val.subject_log.little_question_json,
                    fen: new_val.subject_log.score,
                    flage: true
                })
            }
        },
        bindChange_fen(e) {
            console.log(e);
            this.setData({
                fen: e.detail.value[0]
            })
        },
        popupTap: function (e) {
            this.setData({
                df_popShow: true
            })
        },
        // 关闭弹窗
        closePop: function (e) {
            this.setData({
                df_popShow: false
            })
        },
        // 这个函数内容为空 用于阻止屏幕滚动
        preventTouchMove: function (e) {
        },
        dafen() {
            this.setData({
                df_popShow: false
            })
            this.sure()
        },
        //ask_id	1	是	string	小问项id
        // fraction	3	是	string	小问得分
        // answer_content	回答内容	是	string	回答内容
        mk_submit_subject_big(ask_id, fraction, answer_content) {

        },
        //提交按钮

        flage() {
            if (this.data.my_answer.length < 1) {
                wx.showToast({
                    title: '答案不能为空~',
                    icon: "none"
                })
                return false
            }
            this.setData({
                flage: !this.data.flage
            })
        },
        bindmy_answer(e) {
            this.setData({
                my_answer: e.detail.value
            })
        },
        bindchinge(e) {
            this.setData({
                fen: e.detail.value
            })
        },
        sure() {//填分数的确认
            if (this.data.fen.length == 0) {
                wx.showToast({
                    title: '保存分数失败，请重新选择',
                    icon: 'none'
                })
                return
            }
            if (this.data.fen > this.data.subjectInfo.fraction) {
                wx.showToast({
                    title: '自评分不能超过题目满分',
                    icon: 'none'
                })
                return
            }
            var pageArr = getCurrentPages();
            var thisPage = pageArr[pageArr.length - 1];
            if (this.data.type == 2) {//考试需单独处理分
                thisPage.setData({
                    [`items2[${this.data.num}].fen`]: this.data.fen,
                    [`items2[${this.data.num}].my_answer`]: this.data.my_answer,
                    [`items2[${this.data.num}].is_correct`]: 1 //记录这道题做了
                })
            } else {//正常的提交答案
                // thisPage.submit()
            }
            // thisPage.submit()
            this.mk_submit_subject_big()
            wx.showToast({
                title: '保存成功',
                icon: 'none'
            })
        }
    }
})




